#ifndef _HJDEBUG_H
#define _HJDEBUG_H

#include "hj212_client_config.h"

#ifndef HJ212_DEBUG_ENABLE
    #define HJ212_DEBUG_ENABLE          (0)
#endif

#if HJ212_DEBUG_ENABLE != 0
    #define HJ_DEBUG_ENABLE
#endif

/* 日志标签 */
#ifndef HJ_LOG_TAG
    #define HJ_LOG_TAG "hj212"
    #ifdef HJ_DEBUG_ENABLE
        #warning Please define the HJ_LOG_TAG otherwise the default is "hj212"
    #endif
#endif

/* 日志的静态等级 */
#ifndef HJ_LOG_LVL
    #define HJ_LOG_LVL HJ_DBG_INFO
    #ifdef HJ_DEBUG_ENABLE
        #warning Please define the HJ_LOG_LVL otherwise the default is HJ_DBG_INFO
    #endif
#endif

/* 16进制日志的宽度 */
#ifndef HJ_LOG_HEX_WIDTH
    #define HJ_LOG_HEX_WIDTH (16)    // HEX Width
#endif

/* 字符串日志的结尾 */
#ifndef HJ_LOG_END_MARK
    #define HJ_LOG_END_MARK ("\r\n")    // 结束符
#endif

/* 日志静态等级选项 */
#define HJ_DBG_ERROR    0       // 设备的错误信息
#define HJ_DBG_WARNING  1       // 设备的警告信息
#define HJ_DBG_INFO     2       // 设备运行的信息
#define HJ_DBG_LOG      3       // 调试日志，生产环境中应该去掉这个打印


/* 默认的日志输出接口 */
#ifndef HJ_LOG_OUTPUT
    #include "stdio.h"
    #define HJ_LOG_OUTPUT(...) printf(__VA_ARGS__)
#endif


/* Begin */
#ifndef HJ_DBG_LOG_BEGIN
    #define HJ_DBG_LOG_BEGIN(lvl_name, color_n) HJ_LOG_OUTPUT("\033["#color_n"m[" lvl_name"/" HJ_LOG_TAG"] ")
#endif
/* End */
#ifndef HJ_DBG_LOG_END
    #define HJ_DBG_LOG_END() HJ_LOG_OUTPUT("\033[0m%s", HJ_LOG_END_MARK)
#endif
/* 打印一行日志 */
#ifndef HJ_DBG_LOG_LINE
#define HJ_DBG_LOG_LINE(lvl, color_n, ...)          \
        do                                          \
        {                                           \
        HJ_DBG_LOG_BEGIN(lvl, color_n);             \
        HJ_LOG_OUTPUT(__VA_ARGS__);                 \
        HJ_DBG_LOG_END();                           \
        } while (0)
#endif
/* 打印16进制数据 */
#ifndef HJ_DBG_LOG_HEX
#include <stdint.h>
void hj_dump_hex(const uint8_t *ptr, int buflen, int witdh);
#define HJ_DBG_LOG_HEX(lvl, color_n, buffer, len, ...)      \
        do                                                  \
        {                                                   \
        HJ_DBG_LOG_BEGIN(lvl, color_n);                     \
        HJ_LOG_OUTPUT("[len:%d] ", (int)len);               \
        HJ_LOG_OUTPUT(__VA_ARGS__);                         \
        HJ_LOG_OUTPUT(HJ_LOG_END_MARK);                     \
        hj_dump_hex(buffer, len, HJ_LOG_HEX_WIDTH);         \
        HJ_DBG_LOG_END();                                   \
        } while (0)
#endif

#ifdef HJ_DEBUG_ENABLE
    #define _HJ_DBG_LOG_LINE(lvl, color_n, ...)                 HJ_DBG_LOG_LINE(lvl, color_n, ##__VA_ARGS__)
    #define _HJ_DBG_LOG_HEX(lvl, color_n, buffer, len, ...)     HJ_DBG_LOG_HEX(lvl, color_n, buffer, len, ##__VA_ARGS__)
#else
    #define _HJ_DBG_LOG_LINE(lvl, color_n, ...)
    #define _HJ_DBG_LOG_HEX(lvl, color_n, buffer, len, ...)
#endif

/* 日志总开关 */
#if (HJ_LOG_LVL >= HJ_DBG_LOG)
    #define HJ_LOG_D(...)                       _HJ_DBG_LOG_LINE("D", 0, ##__VA_ARGS__)
    #define HJ_LOGH_D(buffer, len, ...)         _HJ_DBG_LOG_HEX("D", 0, buffer, len, ##__VA_ARGS__)
    #define HJ_LOG_HERE()                       HJ_LOG_D("Here [%s/%s:%d]", __FILE__, __FUNCTION__, __LINE__)
#else
    #define HJ_LOG_D(...)
    #define HJ_LOGH_D(buffer, len, ...)
    #define HJ_LOG_HERE()
#endif

#if (HJ_LOG_LVL >= HJ_DBG_INFO)
    #define HJ_LOG_I(...)                  _HJ_DBG_LOG_LINE("I", 32, ##__VA_ARGS__)
    #define HJ_LOGH_I(buffer, len, ...)    _HJ_DBG_LOG_HEX("I", 32, buffer, len, ##__VA_ARGS__)
#else
    #define HJ_LOG_I(...)
    #define HJ_LOGH_I(buffer, len, ...)
#endif

#if (HJ_LOG_LVL >= HJ_DBG_WARNING)
    #define HJ_LOG_W(...)                  _HJ_DBG_LOG_LINE("W", 33, ##__VA_ARGS__)
    #define HJ_LOGH_W(buffer, len, ...)    _HJ_DBG_LOG_HEX("W", 33, buffer, len, ##__VA_ARGS__)
#else
    #define HJ_LOG_W(...)
    #define HJ_LOGH_W(buffer, len, ...)
#endif

#if (HJ_LOG_LVL >= HJ_DBG_ERROR)
    #define HJ_LOG_E(...)                  _HJ_DBG_LOG_LINE("E", 31, ##__VA_ARGS__)
    #define HJ_LOGH_E(buffer, len, ...)    _HJ_DBG_LOG_HEX("E", 31, buffer, len, ##__VA_ARGS__)
#else
    #define HJ_LOG_E(...)
    #define HJ_LOGH_E(buffer, len, ...)
#endif

/* 普通日志 */
#define HJ_LOG_RAW(...)             // Raw data
#define HJ_LOG_HEX(...)             // Hex data











#endif

